"""
插件基类定义
"""
from abc import ABC, abstractmethod
from typing import Dict, Any, Optional, List
from pydantic import BaseModel
from datetime import datetime


class PluginInfo(BaseModel):
    """插件信息模型"""
    name: str
    version: str
    description: str
    author: str
    homepage: Optional[str] = None
    dependencies: List[str] = []
    tags: List[str] = []
    created_at: datetime
    updated_at: datetime


class PluginConfig(BaseModel):
    """插件配置模型"""
    enabled: bool = False
    settings: Dict[str, Any] = {}
    auto_start: bool = False


class BasePlugin(ABC):
    """插件基类"""
    
    def __init__(self):
        self.info: Optional[PluginInfo] = None
        self.config: Optional[PluginConfig] = None
        self.is_loaded: bool = False
        self.is_active: bool = False
    
    @abstractmethod
    def get_info(self) -> PluginInfo:
        """获取插件信息"""
        pass
    
    @abstractmethod
    def initialize(self) -> bool:
        """初始化插件"""
        pass
    
    @abstractmethod
    def start(self) -> bool:
        """启动插件"""
        pass
    
    @abstractmethod
    def stop(self) -> bool:
        """停止插件"""
        pass
    
    @abstractmethod
    def get_routes(self) -> List[Dict[str, Any]]:
        """获取插件路由"""
        pass
    
    def get_config(self) -> PluginConfig:
        """获取插件配置"""
        return self.config or PluginConfig()
    
    def set_config(self, config: PluginConfig) -> None:
        """设置插件配置"""
        self.config = config
    
    def get_status(self) -> Dict[str, Any]:
        """获取插件状态"""
        return {
            "loaded": self.is_loaded,
            "active": self.is_active,
            "info": self.info.dict() if self.info else None,
            "config": self.config.dict() if self.config else None
        } 